/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session.stateless;

import javax.ejb.Stateless;
import entity.Employee;  
import javax.persistence.EntityManager; 
import javax.persistence.NoResultException; 
import javax.persistence.PersistenceContext; 
import javax.persistence.Query;

/**
 *
 * @author Vincent
 */
@Stateless
public class EmployeeSessionBean implements EmployeeSessionBeanLocal {

    @PersistenceContext 
    private EntityManager entityManager; 
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
    public Employee getEmployee(String userName){
        Query query = entityManager.createQuery("SELECT e FROM Employee e WHERE e.userName = :inUserName"); 
        query.setParameter("inUserName", userName); 
 
        Employee employee = null; 
         
        try 
        { 
            employee = (Employee)query.getSingleResult(); 
        } 
        catch(NoResultException ex) 
        { 
            ex.printStackTrace(); 
        } 
        return employee;
    }
    
    @Override
    public Long getEmployeeId(String userName){
         Query query = entityManager.createQuery("SELECT e.id FROM Employee e WHERE e.userName = :inUserName"); 
        query.setParameter("inUserName", userName); 
        System.out.println("AAAAAAAAAAAAAAAAAAAA");
        Long employeeId = null; 
         
        try 
        { 
            employeeId = (Long)query.getSingleResult(); 
        } 
        catch(NoResultException ex) 
        { 
            ex.printStackTrace(); 
        } 
        return employeeId;
    } 
}
